#include <iostream>
using namespace std;
#include <unistd.h>
#include "Command.hpp"
int main()
{
    char buf[1024];
    SetNonBlock(0);
    cout << "Enter:";

    while (1)
    {
        fflush(stdout);
        ssize_t n = ::read(0, buf, sizeof(buf) - 1);
        if (n > 0)
        {
            buf[n - 1] = 0;
            cout << "echo:" << buf << endl;
        }
        else if (n == 0)
        {
            cout << "read over!" << endl;
            break;
        }
        else
        {
            // 非阻塞调用读取会失败 底层没就绪就会把errno设置为EWOULDBLOCK 或 EAGAIN
            if (errno == EWOULDBLOCK || errno == EAGAIN)
            {
                cout << "continue" << endl;
                sleep(1);
            }
            else
            {
                cerr << errno << endl;
                break;
            }
        }
    }
    return 0;
}